package com.oocl.euc.core.maintenance.repository;

import com.oocl.euc.core.builder.ApplicationKeyBuilder;
import com.oocl.euc.core.common.ITTestBase;
import com.oocl.euc.core.maintenance.model.ApplicationKey;
import org.junit.After;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import java.util.ArrayList;
import java.util.List;

import static org.junit.Assert.*;

public class ApplicationKeyRepositoryIT extends ITTestBase {
    private List<Long> applicationKeyIds = new ArrayList<>();

    @Autowired
    ApplicationKeyBuilder applicationKeyBuilder;

    @Autowired
    ApplicationKeyRepository applicationKeyRepository;

    @After
    public void tearDown() throws Exception {
        applicationKeyRepository.deleteAll();
    }

    @Test
    public void should_return_application_key_when_given_app_key() {
        ApplicationKey applicationKey = applicationKeyBuilder.defaultBuilder()
                .withAppKey("TEST APP KEY")
                .saveToDB();
        ApplicationKey appKey = applicationKeyRepository.findByAppKey(applicationKey.getAppKey());
        assertNotNull(appKey);
        assertEquals("TEST APP KEY", appKey.getAppKey());
    }
}